﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gebra
{
    public class Function
    {
        private readonly Operand _expression;
        private readonly Variable[] _variables;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="a_expression">Expression operand.</param>
        /// <param name="a_variables">Function variables.</param>
        public Function(Operand a_expression, params Variable[] a_variables)
        {
            _expression = a_expression;
            _variables = a_variables;
        }

        /// <summary>
        /// Evaluate the function.
        /// </summary>
        /// <param name="a_values">Variable values.</param>
        /// <returns>Value of the function.</returns>
        public Operand Evaluate(params Operand[] a_values)
        {
            for (var i = 0; i < _variables.Length; i++)
                _variables[i].SetValue(i < a_values.Length ? a_values[i] : new None());

            return _expression.Evaluate();
        }
    }
}
